<?
if(!$_SESSION['memberID']){exit("<script>window.location='dlogin.html'</script>");}
include("../../com.inc.php");
$ac=$GLOBALS['_ac'];
$pw=$GLOBALS['_pw'];
$InSide = new SoapClient(null,array("location" => "http://localhost/open/openService/pft_insideMX.php","uri" => "www.16u.com?ac_16u=$ac|pw_16u=$pw|auth_16u=true")); //票付通内部接口地址
$OutSide=new SoapClient("http://open.12301.cc/openService/MXSE.wsdl",array('encoding' =>'UTF-8','cache_wsdl' => 0));//票付通外部接口地址
$sel="select dname,account from pft_member where id={$_SESSION['memberID']} LIMIT 1";
$GLOBALS['le']->query($sel);
$GLOBALS['le']->fetch_assoc();
$oname=$GLOBALS['le']->f("dname");
$account=$_SESSION['saccount']; //账号
$jk_pw=$InSide->Create_Conn_REC($account,$oname); //接口密码


$orders = str_replace("，",",",$_REQUEST['order']);
$orders = explode(",",$orders);

$order_array = array();

foreach($orders as $k=>$v){
	// $get_order = $InSide->PFT_Order_Code($_SESSION['memberID'],$v,-1);
	// $result=simplexml_load_string($get_order);
	// $ordernum = (string)$result->Rec->UUordernum;
	
	$order_data = $InSide->Order_Globle_Search("", "", "", "", "", "", "", "", "", "", "", "", $v, "", "", "", "", "", "", "1", "0", "15", "0", "0", "", "0", "", "0", "", "", "", "0", "0", "0");
	$order_data_xml = simplexml_load_string($order_data);
	$name = $order_data_xml->Rec->UUordername ; //订单姓名
	$tel = $order_data_xml->Rec->UUordertel ;  //订单手机
	$buyid = $order_data_xml->Rec->UUbuyid ;  //购买者id
	$order_status = (int)$order_data_xml->Rec->UUstatus; //订单状态
	if(!empty($order_data_xml)  && $tel=='12301' && $buyid == $_SESSION['sid']){
		if($order_status == 3){
			$order_array[$v] = 3; //已取消的订单
		}else{
			$cancel_order = $OutSide->__soapCall("Order_Change_Pro",array("ac"=>$account,"pw"=>$jk_pw,"in0"=>$v,"in1"=>0,"in2"=>''));
			$cancel_order_xml = simplexml_load_string($cancel_order);
			if($cancel_order_xml->Rec->UUdone == 100){
				$order_array[$v] =  0; //取消成功
			}else{
				$order_array[$v] =  1; //取消失败
			}
		}

	}else{
		$order_array[$v] = 2; //不是此账号的订单
	}
}
if($order_array[$v] == 0){
	echo "<script>alert('取消成功');location.href='../exportCode.html';</script>";
}elseif($order_array[$v] == 1){
	echo "<script>alert('订单不是未使用状态，无法执行取消操作');location.href='../exportCode.html';</script>";
}elseif($order_array[$v] == 2){
	echo "<script>alert('不属于购买者的导码订单，无法执行取消操作');location.href='../exportCode.html';</script>";
}elseif($order_array[$v] == 3){
	echo "<script>alert('订单已是取消的状态，请勿重复操作');location.href='../exportCode.html';</script>";
}
// print_r($order_array[$v]);
?>